<?php
/***********************************************
	This class would save the image in the
	server.
************************************************/
class ImageSaver {
	private $imageFile = NULL;
	private $createdImage = NULL;
	
	/************************************************************/
	
	function saveImage($image, $imageFilePath) {
		$this->imageFile = fopen($imageFilePath, 'w');
		fwrite($this->imageFile, $image);
		fclose($this->imageFile);
		
		if (exif_imagetype($imageFilePath) == IMAGETYPE_JPEG) {
			$this->createdImage = imagecreatefromjpeg($imageFilePath);
			return $this->createdImage;
		} elseif (exif_imagetype($imageFilePath) == IMAGETYPE_PNG) {
			$this->createdImage = imagecreatefrompng($imageFilePath);
			return $this->createdImage;
		} elseif (exif_imagetype($imageFilePath) == IMAGETYPE_GIF) {
			$this->createdImage = imagecreatefrompng($imageFilePath);
			return $this->createdImage;
		}
	}
}
?>